CREATE TABLE common_Module_Access
(
	ModuleAccessId uniqueidentifier NOT NULL,
        Module VARCHAR(50),
	InitialDate DATETIME,
	FinalDate DATETIME,
	DefaultEntityId uniqueidentifier,
	UserId uniqueidentifier NOT NULL,
	CreationDate DATETIME,
	PRIMARY KEY (ModuleAccessId),
	FOREIGN KEY (UserId) REFERENCES common_User(UserId) 
	ON DELETE NO ACTION 
	ON UPDATE NO ACTION
)  
go
-- INSERT INTO common_Module_Access(ModuleAccessId, Module, InitialDate, FinalDate, UserId, CreationDate) 
		-- VALUES (1,'1',GETDATE(),GETDATE(),1, GETDATE())
		go
		
CREATE TABLE common_Data_Access_Agencia_Config
(
	DataAccessAgenciaConfigId uniqueidentifier NOT NULL,
        Role VARCHAR(50),
	IsActive bit,
	AgenciaId uniqueidentifier NOT NULL,
	ModuleAccessId uniqueidentifier NOT NULL,
        CreationDate DATETIME,
	PRIMARY KEY (DataAccessAgenciaConfigId),
	FOREIGN KEY (AgenciaId) REFERENCES common_Agencia(AgenciaId) 
	ON DELETE NO ACTION 
	ON UPDATE NO ACTION,
	FOREIGN KEY (ModuleAccessId) REFERENCES common_Module_Access(ModuleAccessId) 
	ON DELETE NO ACTION 
	ON UPDATE NO ACTION
) 
GO
-- INSERT INTO common_Data_Access_Agencia_Config(DataAccessAgenciaConfigId, Role, IsActive, AgenciaId, ModuleAccessId, CreationDate) 
	-- VALUES (1,'12','TRUE',1,1, GETDATE());
		
CREATE TABLE common_Data_Access_Agencia_Conta
(
	DataAccessAgenciaContaId uniqueidentifier NOT NULL,
        "Role" VARCHAR(50),
	IsActive bit,
	AgenciaId uniqueidentifier NOT NULL,
	ModuleAccessId uniqueidentifier NOT NULL,
        CreationDate DATETIME,
	PRIMARY KEY (DataAccessAgenciaContaId),
	FOREIGN KEY (AgenciaId) REFERENCES common_Agencia(AgenciaId) 
	ON DELETE NO ACTION 
	ON UPDATE NO ACTION,
	FOREIGN KEY (ModuleAccessId) REFERENCES common_Module_Access(ModuleAccessId) 
	ON DELETE NO ACTION 
	ON UPDATE NO ACTION
)  
GO
